import React, { ReactNode } from 'react'
import {
  View,
  Text
} from 'react-native'
import { NavigationScreenProps } from 'react-navigation'
import BasePage from '../common/basePage'

interface State {
  second: number;
}
export default class WelcomePage extends BasePage {
  public state: State = {
    second: 3
  }

  public static navigationOptions = {
    title: 'Home'
  }

  public constructor (props: NavigationScreenProps) {
    super(props)
    this.state = {
      second: 3
    }
  }

  public componentDidMount (): void {
    const timer = setInterval((): void => {
      if (this.state.second <= 0) {
        clearInterval(timer)
        this._navigate('Sign')
        return
      }
      this.setState({
        second: this.state.second - 1
      })
    }, 1000)
  }

  public render (): ReactNode {
    return (
      <View>
        <Text>WelcomePage</Text>
        <Text>欢迎页需要美化</Text>
        <Text>欢迎倒计时：{this.state.second}</Text>
      </View>
    )
  }
}
